package com.kotlin.hxh.ui.fragment.third.child.child

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.kotlin.hxh.R
import com.kotlin.hxh.base.BaseMainFragment
import com.kotlin.hxh.ui.fragment.CycleFragment
import com.kotlin.hxh.ui.fragment.third.child.ShopFragment
import kotlinx.android.synthetic.main.fragment_content.*



/**
 * @author huxh
 * @date 2018/12/20.
 */
class ContentFragment : BaseMainFragment() {
    private var mMenu: String? = null

    companion object {
        private val ARG_MENU = "arg_menu"

        @JvmStatic
        fun newInstance(menu: String): ContentFragment {
            val args = Bundle()
            args.putString(ARG_MENU, menu)
            val fragment = ContentFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mMenu = arguments?.getString(ARG_MENU)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) = inflater.inflate(R.layout.fragment_content, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView() {
        tv_content.text = "Content:\n$mMenu"
        btn_next.setOnClickListener {
            if (parentFragment is ShopFragment) {
                (parentFragment as ShopFragment).start(CycleFragment.newInstance(1))
            }
        }
    }

    override fun onBackPressedSupport(): Boolean {
        // ContentFragment是ShopFragment的栈顶子Fragment,可以在此处理返回按键事件
        return super.onBackPressedSupport()
    }
}